package Leetcode.排序;

import java.util.Arrays;

/**
 * @ClassName 冒泡
 * @since: 2023/9/14 20:37
 * @auth: kirito
 * @description:
 **/
public class 冒泡 {
    public static void commonSort(int[] arr) {
        int n = arr.length;
        for (int i = 0; i < n - 1; i++) {
            //是否有序标志位
            boolean flag = false;
            for (int j = 0; j < n - i - 1; j++) {
                if (arr[j] > arr[j + 1]) {
                    SortUtils.swap(arr,j,j+1);
                    flag = true;
                }
            }
            //本躺冒泡没有发生交换就证明已经有序
            if (!flag) {
                return;
            }
        }
    }

    public static void main(String[] args) {
        int[] arr = {53,87,12,61,98,17,89,25,63,42};
        commonSort  (arr);
        System.out.println(Arrays.toString(arr));
    }
}
